brewery.queries.test.js ➔ ... ➔ newBrewery.save   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 22

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
c 1
b 0
f 0
nc 1
nop 2
dl 0
loc 22
rs 9.2
1
var chai     = require('chai');
2
var chaiHttp = require('chai-http');
3
var should   = chai.should();
4
5
var server      = require('../../index');
6
var Beer        = require('../../models/beer.model');
7
var Brewery     = require('../../models/brewery.model');
8
var BeerData    = require('../../beers.json');
9
var BreweryData = require('../../breweries.json');
10
11
chai.use(chaiHttp);
12
13
describe('GraphQL Brewery (queries)', function() {
14
15
  beforeEach(function(done){
16
    BreweryData.forEach(function (aBeer) {
17
      var newBrewery = new Brewery(aBeer);
18
      newBrewery.save();
19
    });
20
    BeerData.forEach(function (aBeer) {
21
      var newBeer = new Beer(aBeer);
22
      newBeer.save();
23
    });
24
    done();
25
  });
26
27
  afterEach(function(done){
28
    Beer.collection.drop();
29
    Brewery.collection.drop();
30
    done();
31
  });
32
33
  it('should display all the breweries', function(done) {
34
    var graphqlQuery = `
35
      {
36
        breweries {
37
          name
38
          location
39
        }
40
      }
41
    `;
42
43
    chai.request(server)
44
      .post('/graphql')
45
      .send({query: graphqlQuery})
46
      .end(function(err, res){
47
        res.should.have.status(200);
48
        res.should.be.a.json;
0 ignored issues
show
introduced by
The result of the property access to res.should.be.a.json is not used.
Loading history...
49
        res.body['data']['breweries'].should.be.an('array');
50
        res.body['data']['breweries'][0].should.have.property('name');
51
        res.body['data']['breweries'][0].should.have.property('location');
52
        done();
53
      });
54
  });
55
56
  it('should display a SINGLE brewery', function(done) {
57
    var newBrewery = new Brewery({
58
      _id: 'test_brewery',
59
      name: 'Test Brewery',
60
      location: 'Beerland'
61
    });
62
63
    newBrewery.save(function(err, data) {
64
65
      var graphqlQuery = `
66
      {
67
        brewery(id: "${data._id}") {
68
          name
69
          location
70
        }
71
      }`;
72
73
      chai.request(server)
74
        .post('/graphql')
75
        .send({query: graphqlQuery})
76
        .end(function(err, res){
77
          res.should.have.status(200);
78
          res.should.be.a.json;
0 ignored issues
show
introduced by
The result of the property access to res.should.be.a.json is not used.
Loading history...
79
          res.body.should.be.an('object');
80
          res.body['data']['brewery']['name'].should.equal('Test Brewery');
81
          res.body['data']['brewery']['location'].should.equal('Beerland');
82
          done();
83
        });
84
    });
85
  });
86
});
87